Imports System.Data
Imports System.Xml
Imports System.Data.SqlClient
Imports AppsUtility.EncDec
Imports System.Configuration

Public Class frmARledgerReport
    Inherits System.Windows.Forms.Form
    Dim util As New AppsUtility.EncDec
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Public strCon As String = util.toDecrypt(ConfigurationManager.AppSettings("SQLString")).Replace("serps", CurrentDB)

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents dtpFromDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents dtpToDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents dgTrxEnq As System.Windows.Forms.DataGrid
    Friend WithEvents tbOpbal As System.Windows.Forms.TextBox
    Friend WithEvents tbTotalDr As System.Windows.Forms.TextBox
    Friend WithEvents tbTotalCr As System.Windows.Forms.TextBox
    Friend WithEvents tbClBal As System.Windows.Forms.TextBox
    Friend WithEvents btPrint As System.Windows.Forms.Button
    Friend WithEvents btDisplay As System.Windows.Forms.Button
    Friend WithEvents btClose As System.Windows.Forms.Button
    Friend WithEvents cmbCompany As System.Windows.Forms.ComboBox
    Friend WithEvents cmbGroup1 As System.Windows.Forms.ComboBox

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmARledgerReport))
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btPrint = New System.Windows.Forms.Button
        Me.btDisplay = New System.Windows.Forms.Button
        Me.btClose = New System.Windows.Forms.Button
        Me.Label8 = New System.Windows.Forms.Label
        Me.tbOpbal = New System.Windows.Forms.TextBox
        Me.tbTotalDr = New System.Windows.Forms.TextBox
        Me.Label9 = New System.Windows.Forms.Label
        Me.tbTotalCr = New System.Windows.Forms.TextBox
        Me.tbClBal = New System.Windows.Forms.TextBox
        Me.Label10 = New System.Windows.Forms.Label
        Me.dtpFromDate = New System.Windows.Forms.DateTimePicker
        Me.dtpToDate = New System.Windows.Forms.DateTimePicker
        Me.dgTrxEnq = New System.Windows.Forms.DataGrid
        Me.cmbCompany = New System.Windows.Forms.ComboBox
        Me.cmbGroup1 = New System.Windows.Forms.ComboBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        CType(Me.dgTrxEnq, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(320, 45)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(54, 18)
        Me.Label2.TabIndex = 53
        Me.Label2.Text = "To Date"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(205, 45)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 18)
        Me.Label1.TabIndex = 51
        Me.Label1.Text = "From Date"
        '
        'btPrint
        '
        Me.btPrint.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btPrint.Image = CType(resources.GetObject("btPrint.Image"), System.Drawing.Image)
        Me.btPrint.Location = New System.Drawing.Point(82, 11)
        Me.btPrint.Name = "btPrint"
        Me.btPrint.Size = New System.Drawing.Size(28, 24)
        Me.btPrint.TabIndex = 74
        '
        'btDisplay
        '
        Me.btDisplay.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btDisplay.Image = CType(resources.GetObject("btDisplay.Image"), System.Drawing.Image)
        Me.btDisplay.Location = New System.Drawing.Point(50, 11)
        Me.btDisplay.Name = "btDisplay"
        Me.btDisplay.Size = New System.Drawing.Size(28, 24)
        Me.btDisplay.TabIndex = 71
        '
        'btClose
        '
        Me.btClose.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btClose.Image = CType(resources.GetObject("btClose.Image"), System.Drawing.Image)
        Me.btClose.Location = New System.Drawing.Point(18, 11)
        Me.btClose.Name = "btClose"
        Me.btClose.Size = New System.Drawing.Size(28, 24)
        Me.btClose.TabIndex = 70
        '
        'Label8
        '
        Me.Label8.AutoSize = True
        Me.Label8.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label8.Location = New System.Drawing.Point(684, 68)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(88, 18)
        Me.Label8.TabIndex = 81
        Me.Label8.Text = "Opg .Balance"
        '
        'tbOpbal
        '
        Me.tbOpbal.BackColor = System.Drawing.Color.White
        Me.tbOpbal.Location = New System.Drawing.Point(778, 68)
        Me.tbOpbal.Name = "tbOpbal"
        Me.tbOpbal.ReadOnly = True
        Me.tbOpbal.Size = New System.Drawing.Size(121, 26)
        Me.tbOpbal.TabIndex = 82
        Me.tbOpbal.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'tbTotalDr
        '
        Me.tbTotalDr.BackColor = System.Drawing.Color.White
        Me.tbTotalDr.Location = New System.Drawing.Point(654, 418)
        Me.tbTotalDr.Name = "tbTotalDr"
        Me.tbTotalDr.ReadOnly = True
        Me.tbTotalDr.Size = New System.Drawing.Size(121, 26)
        Me.tbTotalDr.TabIndex = 84
        Me.tbTotalDr.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label9
        '
        Me.Label9.AutoSize = True
        Me.Label9.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label9.Location = New System.Drawing.Point(615, 418)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(38, 18)
        Me.Label9.TabIndex = 83
        Me.Label9.Text = "Total"
        '
        'tbTotalCr
        '
        Me.tbTotalCr.BackColor = System.Drawing.Color.White
        Me.tbTotalCr.Location = New System.Drawing.Point(778, 418)
        Me.tbTotalCr.Name = "tbTotalCr"
        Me.tbTotalCr.ReadOnly = True
        Me.tbTotalCr.Size = New System.Drawing.Size(121, 26)
        Me.tbTotalCr.TabIndex = 85
        Me.tbTotalCr.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'tbClBal
        '
        Me.tbClBal.BackColor = System.Drawing.Color.White
        Me.tbClBal.Location = New System.Drawing.Point(778, 450)
        Me.tbClBal.Name = "tbClBal"
        Me.tbClBal.ReadOnly = True
        Me.tbClBal.Size = New System.Drawing.Size(121, 26)
        Me.tbClBal.TabIndex = 87
        Me.tbClBal.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label10
        '
        Me.Label10.AutoSize = True
        Me.Label10.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label10.Location = New System.Drawing.Point(678, 451)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(82, 18)
        Me.Label10.TabIndex = 86
        Me.Label10.Text = "Clg. Balance"
        '
        'dtpFromDate
        '
        Me.dtpFromDate.Format = System.Windows.Forms.DateTimePickerFormat.[Short]
        Me.dtpFromDate.Location = New System.Drawing.Point(206, 65)
        Me.dtpFromDate.Name = "dtpFromDate"
        Me.dtpFromDate.Size = New System.Drawing.Size(109, 26)
        Me.dtpFromDate.TabIndex = 153
        '
        'dtpToDate
        '
        Me.dtpToDate.Format = System.Windows.Forms.DateTimePickerFormat.[Short]
        Me.dtpToDate.Location = New System.Drawing.Point(321, 65)
        Me.dtpToDate.Name = "dtpToDate"
        Me.dtpToDate.Size = New System.Drawing.Size(114, 26)
        Me.dtpToDate.TabIndex = 154
        '
        'dgTrxEnq
        '
        Me.dgTrxEnq.BackColor = System.Drawing.Color.AliceBlue
        Me.dgTrxEnq.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.dgTrxEnq.CaptionVisible = False
        Me.dgTrxEnq.DataMember = ""
        Me.dgTrxEnq.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgTrxEnq.Location = New System.Drawing.Point(15, 100)
        Me.dgTrxEnq.Name = "dgTrxEnq"
        Me.dgTrxEnq.PreferredColumnWidth = 175
        Me.dgTrxEnq.ReadOnly = True
        Me.dgTrxEnq.Size = New System.Drawing.Size(884, 308)
        Me.dgTrxEnq.TabIndex = 155
        Me.dgTrxEnq.TabStop = False
        '
        'cmbCompany
        '
        Me.cmbCompany.BackColor = System.Drawing.Color.AliceBlue
        Me.cmbCompany.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbCompany.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmbCompany.ItemHeight = 18
        Me.cmbCompany.Location = New System.Drawing.Point(183, 224)
        Me.cmbCompany.Name = "cmbCompany"
        Me.cmbCompany.Size = New System.Drawing.Size(208, 26)
        Me.cmbCompany.TabIndex = 88
        Me.cmbCompany.Visible = False
        '
        'cmbGroup1
        '
        Me.cmbGroup1.BackColor = System.Drawing.Color.AliceBlue
        Me.cmbGroup1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbGroup1.Location = New System.Drawing.Point(15, 65)
        Me.cmbGroup1.Name = "cmbGroup1"
        Me.cmbGroup1.Size = New System.Drawing.Size(185, 26)
        Me.cmbGroup1.TabIndex = 157
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label3.Location = New System.Drawing.Point(180, 204)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(66, 18)
        Me.Label3.TabIndex = 81
        Me.Label3.Text = "Company"
        Me.Label3.Visible = False
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label4.Location = New System.Drawing.Point(15, 45)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(109, 18)
        Me.Label4.TabIndex = 81
        Me.Label4.Text = "Customer Group"
        '
        'ARledgerReport
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(914, 486)
        Me.ControlBox = False
        Me.Controls.Add(Me.tbOpbal)
        Me.Controls.Add(Me.cmbGroup1)
        Me.Controls.Add(Me.dgTrxEnq)
        Me.Controls.Add(Me.dtpToDate)
        Me.Controls.Add(Me.dtpFromDate)
        Me.Controls.Add(Me.tbClBal)
        Me.Controls.Add(Me.tbTotalCr)
        Me.Controls.Add(Me.tbTotalDr)
        Me.Controls.Add(Me.Label10)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label8)
        Me.Controls.Add(Me.btPrint)
        Me.Controls.Add(Me.btDisplay)
        Me.Controls.Add(Me.btClose)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.cmbCompany)
        Me.Controls.Add(Me.Label3)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ForeColor = System.Drawing.SystemColors.ControlLightLight
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(50, 70)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "ARledgerReport"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        CType(Me.dgTrxEnq, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private Sub Budgets_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ICdata As New ICdataLogic
        Dim ds, ds2 As DataSet
        ds = ICdata.GetAllCompany()
        cmbCompany.DataSource = ds.Tables(0)
        cmbCompany.ValueMember = "CompanyID"
        cmbCompany.DisplayMember = "CompanyName"
        cmbCompany.SelectedValue = CompanyID
        ds2 = ICdata.GetCompanyCustomers(CompanyID)
        LoadGroupCombos(CompanyID)

    End Sub
    Private Sub LoadGroupCombos(ByVal CompanyCode As Integer)
        Dim ARdata As New ARdataLogic
        Dim ds As DataSet

        ds = ARdata.GetCustomerGroups()
        cmbGroup1.DataSource = ds.Tables(0)
        cmbGroup1.ValueMember = "GroupID"
        cmbGroup1.DisplayMember = "GroupName"
        cmbGroup1.SelectedValue = 0
        '
        ARdata = Nothing
    End Sub
    Private Sub dgTrxEnq_load()
        Try

            Dim GrID As Integer
            If IsNumeric(cmbGroup1.SelectedValue) Then
                GrID = cmbGroup1.SelectedValue
            End If
            Dim strsql As String
            Dim FrDt, ToDt As String
            FrDt = dtpFromDate.Text
            ToDt = dtpToDate.Text
            FrDt = FrDt.Substring(6, 4) & "-" & FrDt.Substring(3, 2) & "-" & FrDt.Substring(0, 2)
            ToDt = ToDt.Substring(6, 4) & "-" & ToDt.Substring(3, 2) & "-" & ToDt.Substring(0, 2)
            Dim sqlCon As SqlConnection = New SqlConnection(strCon)
            sqlCon.Open()
            strsql = "Select SupCode,SupName," & _
            "'OPB' DocNum,'2006-05-31'DocDate,'O' DocType,0 DrAmount,0 DocFcAmt,'' DocFcCode," & _
            "sum(CrAmount) CrAmount,'Balance b/f' DocRefer,'' TrxNumber " & _
            "from (Select SupCode,SupName," & _
            "'OPB' DocNum,'2006-05-31'DocDate,'O' DocType,0 DrAmount,0 DocFcAmt,'' DocFcCode," & _
            "0 CrAmount,'' DocRefer,'' TrxNumber " & _
            "from ApTrx a,Supplier b where a.SupID=b.SupID " & _
            "group by SupCode,SupName,DocType " & _
            "union all " & _
            "Select SupCode,SupName," & _
            "'OPB' DocNum,'2006-05-31'DocDate,'O' DocType,0 DrAmount,0 DocFcAmt,'' DocFcCode," & _
            "Sum(DocAmt) CrAmount,'' DocRefer,'' TrxNumber " & _
            "from ApTrx a,Supplier b where a.SupID=b.SupID  " & _
            "and DocDate<'2006-06-01' " & _
            "group by SupCode,SupName,DocType) x " & _
            "group by SupCode,SupName,DocType " & _
            "union all " & _
            "Select SupCode,SupName," & _
            "DocNum,DocDate,DocType,DocAmt DrAmount,DocFcAmt,DocFcCode,0 CrAmount,DocRefer,TrxNumber " & _
            "from ApTrx a,Supplier b where a.SupID=b.SupID and DocAmt>0 " & _
            "and DocDate between '2006-06-01' and '2006-06-30' " & _
            "union all " & _
            "Select SupCode,SupName," & _
            "DocNum,DocDate,DocType,0 DrAmount,DocFcAmt,DocFcCode,DocAmt CrAmount,DocRefer,TrxNumber " & _
            "from ApTrx a,Supplier b where a.SupID=b.SupID and DocAmt<0 " & _
            "and DocDate between '2006-06-01' and '2006-06-30' " & _
            "union all " & _
            "Select SupCode,SupName," & _
            "'CLB' DocNum,'2006-06-30'DocDate,'G' DocType,0 DrAmount,0 DocFcAmt,'' DocFcCode, " & _
            "Sum(DocAmt) CrAmount,'Closing Balance' DocRefer,'' TrxNumber " & _
            "from ApTrx a,Supplier b where a.SupID=b.SupID " & _
            "and DocDate<='2006-06-30' " & _
            "group by SupCode,SupName,DocType " & _
            "order by SupName,DocDate"
            Dim da As New SqlClient.SqlDataAdapter(strsql, sqlCon)
            Dim ds As New DataSet("TRENQ")
            da.Fill(ds, "TRENQ")
            dgTrxEnq.DataSource = ds
            dgTrxEnq.DataMember = "TRENQ"
            dgTrxEnq.ReadOnly = True
            dgTrxEnq.TableStyles.Clear()
            dgTrxEnq_Style()
            sqlCon.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub dgTrxEnq_Style()
        With dgTrxEnq
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = True
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With

        Dim grdTableStyle As New DataGridTableStyle
        With grdTableStyle
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
            .MappingName = "TRENQ"
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
        End With



        Dim cs As DataGridColumnStyle
        cs = New DataGridTextBoxColumn
        cs.Width = 90
        cs.MappingName = "DocNum"
        cs.HeaderText = "DocNum"
        cs.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs)

        Dim cs1 As DataGridColumnStyle
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 85
        cs1.MappingName = "DocDate"
        cs1.HeaderText = "Date"
        cs1.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs1)

        Dim cs7 As DataGridColumnStyle
        cs7 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs7.Width = 275
        cs7.MappingName = "DocRefer"
        cs7.HeaderText = "Description"
        cs7.NullText = ""
        cs7.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs7)

        Dim cs2 As DataGridColumnStyle
        cs2 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs2.Width = 80
        cs2.MappingName = "DOCTYPE"
        cs2.HeaderText = "TYPE."
        cs2.NullText = ""
        cs2.ReadOnly = True
        'cs2.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs2)



        Dim cs3 As DataGridColumnStyle
        cs3 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs3.Width = 115
        cs3.MappingName = "DrAmount"
        cs3.HeaderText = "Debit Amt"
        cs3.NullText = ""
        cs3.ReadOnly = True
        cs3.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs3)

        Dim cs4 As DataGridColumnStyle
        cs4 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs4.Width = 115
        cs4.MappingName = "CrAmount"
        cs4.HeaderText = "Credit Amt"
        cs4.NullText = ""
        cs4.ReadOnly = True
        cs4.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs4)

        'Dim cs5 As DataGridColumnStyle
        'cs5 = New DataGridTextBoxColumn  ' Add the standard column style.
        'cs5.Width = 80
        'cs5.MappingName = "DrFCAmount"
        'cs5.HeaderText = "Debit FC ."
        'cs5.NullText = ""
        'cs5.ReadOnly = True
        'cs5.Alignment = HorizontalAlignment.Right
        'grdTableStyle.GridColumnStyles.Add(cs5)

        'Dim cs6 As DataGridColumnStyle
        'cs6 = New DataGridTextBoxColumn ' Add the standard column style.
        'cs6.Width = 80
        'cs6.MappingName = "CrFcAmount"
        'cs6.HeaderText = "Credit FC ."
        'cs6.NullText = ""
        'cs6.ReadOnly = True
        'cs6.Alignment = HorizontalAlignment.Right
        'grdTableStyle.GridColumnStyles.Add(cs6)



        'Dim cs8 As DataGridColumnStyle
        'cs8 = New DataGridTextBoxColumn
        'cs8.Width = 35
        'cs8.MappingName = "DocFcCode"
        'cs8.HeaderText = "CCY ."
        'cs8.NullText = ""
        'grdTableStyle.GridColumnStyles.Add(cs8)

        Dim cs9 As DataGridColumnStyle
        cs9 = New DataGridTextBoxColumn
        cs9.Width = 90
        cs9.MappingName = "TrxNumber"
        cs9.HeaderText = "TrxNo ."
        cs9.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs9)

        dgTrxEnq.TableStyles.Add(grdTableStyle)

    End Sub

    'Private Sub Customer_load()
    '    Try
    '        'strsql = "SELECT CustNum,CustName FROM CustomerMaster ORDER BY CustName"
    '        strsql = "Exec ALLCUSTOMER "
    '        If sqlCon.State = ConnectionState.Closed Then
    '            sqlCon.Open()
    '        End If
    '        sqlCmd.CommandText = strsql
    '        Dim da As New SqlClient.SqlDataAdapter(strsql, sqlCon)
    '        Dim ds As New DataSet("SMAN")
    '        da.Fill(ds, "SMAN")
    '        cbCustomer.DataSource = ds.Tables(0)
    '        cbCustomer.DisplayMember = "CustName"
    '        cbCustomer.ValueMember = "CustNum"
    '        cbCustomer.SelectedValue = ""
    '        sqlCon.Close()
    '    Catch ex As Exception
    '        MsgBox(ex.ToString)
    '        Beep()
    '    End Try
    'End Sub
    Private Sub btClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btClose.Click
        Me.Hide()
    End Sub

    Private Sub btDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDisplay.Click
        dgTrxEnq_load()
    End Sub



    'Private Function gridTotal()
    '    Dim rowCount As Integer = dgTrxEnq.BindingContext(dgTrxEnq.DataSource, dgTrxEnq.DataMember).Count
    '    Dim row As Integer = dgTrxEnq.CurrentRowIndex
    '    Dim grosstotal As Double
    '    For row = 0 To rowCount - 1
    '        grosstotal += dgTrxEnq(row, 5)
    '    Next
    '    Return grosstotal
    'End Function

    Private Sub PrintGLTrx(ByVal Pcode As String)
        'Dim ds As DataSet = New DataSet("GLEnqRpt")
        'Dim table As DataTable = New DataTable("GLEnqRpt")
        'table.Columns.Add("TrxDate")
        'table.Columns.Add("TrxSource")
        'table.Columns.Add("DrAmount")
        'table.Columns.Add("CrAmount")
        'table.Columns.Add("TrxRefer")
        'table.Columns.Add("TrxNumber")

        'Dim rowCount As Integer = dgTrxEnq.BindingContext(dgTrxEnq.DataSource, dgTrxEnq.DataMember).Count
        'Dim row As Integer = dgTrxEnq.CurrentRowIndex

        'For row = 0 To rowCount - 1
        '    Dim nrow As DataRow = table.NewRow()
        '    nrow("TrxDate") = dgTrxEnq(row, 0)
        '    nrow("TrxSource") = dgTrxEnq(row, 1)
        '    nrow("DrAmount") = dgTrxEnq(row, 2)
        '    nrow("CrAmount") = dgTrxEnq(row, 3)
        '    nrow("TrxRefer") = dgTrxEnq(row, 4)
        '    nrow("TrxNumber") = dgTrxEnq(row, 5)
        '    table.Rows.Add(nrow)
        'Next

        'Dim FrDt As String = FrDate.Text
        'Dim ToDt As String = ToDate.Text
        'Dim pdesc As String = AccountName.Text

        'ds.Tables.Add(table)

        'iprint.Load(GLEnqPrintPath)
        'iprint.SetDataSource(ds)
        'iprint.SetParameterValue("AccountCode", Pcode)
        'iprint.SetParameterValue("FromDate", FrDt)
        'iprint.SetParameterValue("ToDate", ToDt)
        'iprint.SetParameterValue("AccountName", pdesc)
        'iprint.SetParameterValue("BBFQTY", opbSign.Text)
        'iprint.SetParameterValue("CLOQTY", clbSign.Text)



        ''  Dim AmountWords As String = AmountToWords(Net)
        '' iprint.SetParameterValue("AmountWords", AmountWords)
        ''iprint.SetParameterValue("BOTTOMMESSAGE", btmmsg & vbNewLine & WarSerials)
        '' iprint.PrintOptions.PrinterName = "Epson LQ-300 ESC/P 2"
        ''print.PrintOptions.PrinterName = InvoicePrinter
        'iprint.PrintToPrinter(1, True, 0, 0)
        ''CrystalReportViewer1.ReportSource = iprint
        ''CrystalReportViewer1.Visible = True
    End Sub

    Private Sub btPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btPrint.Click
        Try
            'PrintGLTrx(MainCode.Text)
            btDisplay.PerformClick()
            Dim row As Integer = dgTrxEnq.CurrentRowIndex
            If row >= 0 Then
                PrintSupplier() ' PrintGLTrx(MainCode.Text)
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try


    End Sub


    'Private Sub cbCustomer_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cbCustomer.Validating
    '    Try
    '        strsql = "SELECT CustNum FROM CustomerMaster where CustName='" & _
    '       Q(cbCustomer.Text) & "'"
    '        If sqlCon.State = ConnectionState.Closed Then
    '            sqlCon.Open()
    '        End If
    '        sqlCmd.CommandText = strsql
    '        rdr = sqlCmd.ExecuteReader
    '        Dim scode As String
    '        If rdr.HasRows Then
    '            While rdr.Read
    '                scode = rdr("CustNum")
    '            End While
    '        Else
    '            scode = ""
    '        End If
    '        rdr.Close()
    '        sqlCon.Close()
    '        MainCode.Text = scode
    '    Catch ex As Exception
    '        MsgBox(ex.ToString)
    '    End Try
    'End Sub
    Private Sub PrintSupplier()
        'Try
        '    Dim BBFDate As Date = (Convert.ToDateTime(dtpFromDate.Text)).AddDays(-1)
        '    Dim BBYType As String = "B"
        '    Dim BBFRef As String = "BALANCE B/F"
        '    Dim BBFDrAmt, BBFCrAmt As Double
        '    Dim opAmt As String
        '    Dim ln1 As Integer
        '    opAmt = tbOpbal.Text
        '    ln1 = opAmt.Length
        '    If opAmt <> "" Then
        '        If opAmt.Substring(ln1 - 2, 2) = "Dr" Then
        '            BBFDrAmt = Convert.ToDouble(opAmt.Remove(ln1 - 2, 2))
        '            BBFCrAmt = 0
        '        Else
        '            BBFCrAmt = Convert.ToDouble(opAmt.Remove(ln1 - 2, 2))
        '            BBFDrAmt = 0
        '        End If
        '    End If
        '    Dim Customer As String = "(" & CStr(cbCustomer.SelectedValue) & ") : " & cbCustomer.Text
        '    Dim ds As DataSet = New DataSet("GlTrxEnqRpt")
        '    Dim table As DataTable = New DataTable("GlTrxEnqRpt")
        '    table.Columns.Add("TrxDate")
        '    table.Columns.Add("Type")
        '    table.Columns.Add("TrxSource")
        '    table.Columns.Add("TrxNumber")
        '    table.Columns.Add("DrAmount")
        '    table.Columns.Add("CrAmount")
        '    table.Columns.Add("TrxRefer")


        '    Dim rowCount As Integer = dgTrxEnq.BindingContext(dgTrxEnq.DataSource, dgTrxEnq.DataMember).Count
        '    Dim row As Integer = dgTrxEnq.CurrentRowIndex
        '    For row = 0 To rowCount - 1
        '        Dim nrow As DataRow = table.NewRow()
        '        nrow("TrxDate") = dgTrxEnq(row, 0)
        '        nrow("TrxSource") = dgTrxEnq(row, 1)
        '        nrow("Type") = dgTrxEnq(row, 2)
        '        nrow("DrAmount") = dgTrxEnq(row, 3)
        '        nrow("CrAmount") = dgTrxEnq(row, 4)
        '        nrow("TrxRefer") = dgTrxEnq(row, 5)
        '        nrow("TrxNumber") = dgTrxEnq(row, 6)
        '        table.Rows.Add(nrow)
        '    Next
        '    Dim PP1, PP2, PP3 As String

        '    ds.Tables.Add(table)
        '    iprint.Load(ArTrxEnqPrintPath)
        '    iprint.SetDataSource(ds)
        '    iprint.SetParameterValue("Customername", Customer)
        '    iprint.SetParameterValue("FrDate", FrDate.Text)
        '    iprint.SetParameterValue("ToDate", ToDate.Text)
        '    iprint.SetParameterValue("BBFDate", BBFDate)
        '    iprint.SetParameterValue("BBFDrAmt", Convert.ToDouble(BBFDrAmt))
        '    iprint.SetParameterValue("BBFCrAmt", Convert.ToDouble(BBFCrAmt))
        '    ' iprint.SetParameterValue("BBFCrFc", Convert.ToDouble(BBFCrFcAmt))
        '    '  iprint.SetParameterValue("BBFDrFc", Convert.ToDouble(BBFDrFcAmt))


        '    If PrntPrv Is Nothing Then
        '        PrntPrv = New PrintPreview
        '        PrntPrv.CrRptView.ReportSource = iprint
        '        PrntPrv.ShowDialog()
        '    End If
        '    'iPrint.PrintToPrinter(1, True, 0, 0)
        'Catch ex As Exception
        '    MsgBox(ex.ToString)
        'End Try
    End Sub

    'Private Sub dgPend_load()
    '    Try

    '        FrDt = FrDate.Text
    '        ToDt = ToDate.Text
    '        'strsql = "select DocNum,DocDate,DocType,DocAmt DrAmount,DocRefer," & _
    '        '"TrxNumber,DocPaidAmt,datediff(day,DocDate,getdate()) span from ARTRX where DocCus='" & _
    '        'Q(MainCode.Text) & "' and " & _
    '        '"(DocDate between '" & FrDt & "' and '" & ToDt & "') " & _
    '        '"and DocAmt+DocPaidAmt<>0 and DocType='s' " & _
    '        '" order by DocDate "
    '        strsql = "select DocNum,DocDate,DocType,DocAmt DrAmount,DocRefer," & _
    '        "TrxNumber,DocPaidAmt,datediff(day,DocDate,getdate()) span from ARTRX where DocCus='" & _
    '        Q(MainCode.Text) & "' " & _
    '        "and DocAmt+DocPaidAmt<>0 and DocType='s' " & _
    '        " order by DocDate "
    '        Dim da As New SqlClient.SqlDataAdapter(strsql, sqlCon)
    '        Dim ds As New DataSet("PEND")
    '        da.Fill(ds, "PEND")

    '        dgPend.DataSource = ds
    '        dgPend.DataMember = "PEND"
    '        dgPend.ReadOnly = True
    '        dgPend.TableStyles.Clear()
    '        dgPend_Style()

    '    Catch ex As Exception
    '        MsgBox(ex.ToString)
    '    End Try
    'End Sub

    'Private Sub dgPend_Style()
    '    With dgPend
    '        '.BackColor = Color.GhostWhite
    '        .BackgroundColor = Color.LightBlue 'DarkSlateBlue 'Lavender
    '        .BorderStyle = BorderStyle.None
    '        .CaptionBackColor = Color.RoyalBlue
    '        .CaptionFont = New Font("Tahoma", 10.0!, FontStyle.Bold)
    '        .CaptionForeColor = Color.Bisque 'DarkRed '
    '        .CaptionText = "Product Details"
    '        .Font = New Font("Tahoma", 8.0!)
    '        .ParentRowsBackColor = Color.Lavender
    '        .ParentRowsForeColor = Color.MidnightBlue
    '        .ReadOnly = True
    '    End With

    '    Dim grdTableStyle As New DataGridTableStyle
    '    With grdTableStyle
    '        .AlternatingBackColor = Color.LightSteelBlue 'GhostWhite
    '        .BackColor = Color.PowderBlue 'GhostWhite
    '        .ForeColor = Color.MidnightBlue
    '        .GridLineColor = Color.LightSlateGray 'RoyalBlue
    '        .HeaderBackColor = Color.CadetBlue 'MidnightBlue
    '        .HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
    '        .HeaderForeColor = Color.Lavender
    '        .SelectionBackColor = Color.Teal
    '        .SelectionForeColor = Color.PaleGreen
    '        .MappingName = "PEND"
    '        .PreferredColumnWidth = 160
    '        .PreferredRowHeight = 15
    '    End With


    '    Dim cs As DataGridColumnStyle
    '    cs = New DataGridTextBoxColumn
    '    cs.Width = 80
    '    cs.MappingName = "DocDate"
    '    cs.HeaderText = "Date"
    '    cs.NullText = ""
    '    grdTableStyle.GridColumnStyles.Add(cs)

    '    Dim cs1 As DataGridColumnStyle
    '    cs1 = New DataGridTextBoxColumn
    '    cs1.Width = 70
    '    cs1.MappingName = "DocNum"
    '    cs1.HeaderText = "Doc.No."
    '    cs1.NullText = ""
    '    grdTableStyle.GridColumnStyles.Add(cs1)

    '    Dim cs5 As DataGridColumnStyle
    '    cs5 = New DataGridTextBoxColumn
    '    cs5.Width = 50
    '    cs5.MappingName = "DocType"
    '    cs5.HeaderText = "Type"
    '    cs5.NullText = ""
    '    grdTableStyle.GridColumnStyles.Add(cs5)

    '    Dim cs0 As DataGridColumnStyle
    '    cs0 = New DataGridTextBoxColumn  ' Add the standard column style.
    '    cs0.Width = 80
    '    cs0.MappingName = "DrAmount"
    '    cs0.HeaderText = "Dr. Amount "
    '    cs0.NullText = ""
    '    cs0.ReadOnly = True
    '    cs0.Alignment = HorizontalAlignment.Right
    '    grdTableStyle.GridColumnStyles.Add(cs0)


    '    Dim cs4 As DataGridColumnStyle
    '    cs4 = New DataGridTextBoxColumn  ' Add the standard column style.
    '    cs4.Width = 60
    '    cs4.MappingName = "DocPaidAmt"
    '    cs4.HeaderText = "Paid "
    '    cs4.NullText = ""
    '    cs4.ReadOnly = True
    '    cs4.Alignment = HorizontalAlignment.Right
    '    grdTableStyle.GridColumnStyles.Add(cs4)

    '    Dim cs2 As DataGridColumnStyle
    '    cs2 = New DataGridTextBoxColumn  ' Add the standard column style.
    '    cs2.Width = 140
    '    cs2.MappingName = "DocRefer"
    '    cs2.HeaderText = "Description"
    '    cs2.NullText = ""
    '    cs2.ReadOnly = True
    '    grdTableStyle.GridColumnStyles.Add(cs2)

    '    Dim cs3 As DataGridColumnStyle
    '    cs3 = New DataGridTextBoxColumn
    '    cs3.Width = 80
    '    cs3.MappingName = "TrxNumber"
    '    cs3.HeaderText = "Trx.No."
    '    cs3.NullText = ""
    '    grdTableStyle.GridColumnStyles.Add(cs3)


    '    Dim cs6 As DataGridColumnStyle
    '    cs6 = New DataGridTextBoxColumn
    '    cs6.Width = 70
    '    cs6.MappingName = "Span"
    '    cs6.HeaderText = "Span(Days)"
    '    cs6.NullText = ""
    '    cs6.Alignment = HorizontalAlignment.Center
    '    grdTableStyle.GridColumnStyles.Add(cs6)

    '    dgPend.TableStyles.Add(grdTableStyle)
    'End Sub

    'Private Sub btPend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btPend.Click
    '    Try
    '        PaPend.Visible = True
    '        dgPend_load()
    '    Catch ex As Exception
    '        MsgBox(ex.ToString)
    '    End Try
    'End Sub

    'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '    PaPend.Visible = False
    'End Sub
End Class
